// 生成随机数据，保持一定的增长趋势
function generateRandomData(baseValue, monthCount, minIncrease, maxIncrease) {
  const data = [baseValue];
  let currentValue = baseValue;

  for (let i = 1; i < monthCount; i++) {
    // 生成一个随机增长值，确保总体呈现增长趋势
    const increase = Math.random() * (maxIncrease - minIncrease) + minIncrease;
    currentValue += increase;
    // 保留一位小数
    data.push(Number(currentValue.toFixed(1)));
  }
  return data;
}

// 模拟获取投资数据的接口
export function getInvestmentData() {
  return new Promise((resolve) => {
    // 模拟接口延迟
    setTimeout(() => {
      // 计划投资：从5.8开始，每月增长3-7之间的随机值
      const plannedData = generateRandomData(5.8, 12, 3, 7);

      // 实际投资：从计划投资的85%-115%之间随机
      const actualData = plannedData.slice(0, 9).map((planned) => {
        const ratio = 0.85 + Math.random() * 0.3; // 85% - 115%
        return Number((planned * ratio).toFixed(1));
      });

      resolve({
        code: 200,
        data: {
          planned: plannedData,
          actual: actualData,
        },
      });
    }, 500); // 500ms延迟模拟网络请求
  });
}
